clear

* use "Data Set", replace

* ------------------------------------------------------------------------------
* ----------- Models for Table 4
* ------------------------------------------------------------------------------

eststo clear 

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover /// 
	i1.uncover#i1.down ///
	i1.uncover#i1.up, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down

reghdfe delta_p ln_pyr_dpw /// Commercial
	i1.uncover /// 
	i1.uncover#i1.down ///
	i1.uncover#i1.up ///
	if commercial==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo commercial_up_down

esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst
	
* ------------------------------------------------------------------------------
* ----------- Models for Table 5
* ------------------------------------------------------------------------------

eststo clear 

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover /// 
	i1.uncover#i1.down#i1.high i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down

reghdfe delta_p ln_pyr_dpw /// Commercial
	i1.uncover /// 
	i1.uncover#i1.down#i1.high i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low ///
	if commercial==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo commercial_up_down

esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst 

* ------------------------------------------------------------------------------
* ----------- Models for Table 6
* ------------------------------------------------------------------------------

eststo clear 

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down


reghdfe delta_p ln_pyr_dpw /// Commercial
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up ///
	if commercial==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo commercial_up_down

esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst 

* ------------------------------------------------------------------------------
* ----------- Models for Table 7
* ------------------------------------------------------------------------------

eststo clear 

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover#i1.down#i1.high i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down

reghdfe delta_p ln_pyr_dpw /// Commercial
	i1.uncover#i1.down#i1.high i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low ///
	if commercial==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo commercial_up_down

esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst 

* ------------------------------------------------------------------------------
* ----------- Models for Table 8
* ------------------------------------------------------------------------------

eststo clear 

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down

reghdfe delta_p ln_pyr_dpw /// Commercial
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up ///
	if commercial==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo commercial_up_down

esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst 
	
* ------------------------------------------------------------------------------
* ----------- Models for Table 9
* ------------------------------------------------------------------------------

eststo clear 

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover /// 
	i1.uncover#i1.down#i1.high i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low, ///
	absorb(fly_id fls_id sly_id) vce(cluster fly_id)
eststo up_down

reghdfe delta_p ln_pyr_dpw /// Commercial
	i1.uncover /// 
	i1.uncover#i1.down#i1.high i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low ///
	if commercial==1, ///
	absorb(fly_id fls_id sly_id) vce(cluster fly_id)
eststo commercial_up_down

esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst 
	
* ------------------------------------------------------------------------------
* ----------- Models for Table 10
* ------------------------------------------------------------------------------

eststo clear 

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up, ///
	absorb(fly_id fls_id sly_id) vce(cluster fly_id)
eststo up_down

reghdfe delta_p ln_pyr_dpw /// Commercial
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up ///
	if commercial==1, ///
	absorb(fly_id fls_id sly_id) vce(cluster fly_id)
eststo commercial_up_down

esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst 	

* ------------------------------------------------------------------------------
* ----------- Models for Timing of Growth Response (Figure 6)
* ------------------------------------------------------------------------------

eststo clear

/* set it up as a panel:  Firm-Line-State by Year */
tsset fls_id year

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover /// 
	/* Downgrades (Pre, Current, Post) */  																	///
	i1.uncover#i1f1.down#i1.high 		i1.uncover#i1.down#i1.high 		i1.uncover#i1l1.down#i1.high		///	
	i1.uncover#i1f1.down#i1.a_minus 	i1.uncover#i1.down#i1.a_minus	i1.uncover#i1l1.down#i1.a_minus		///
	i1.uncover#i1f1.down#i1.low			i1.uncover#i1.down#i1.low		i1.uncover#i1l1.down#i1.low 		///
	/* Upgrades (Pre, Current, Post) */  																	///
	i1.uncover#i1f1.up#i1.high 			i1.uncover#i1.up#i1.high		i1.uncover#i1l1.up#i1.high			///  
	i1.uncover#i1f1.up#i1.a_minus		i1.uncover#i1.up#i1.a_minus		i1.uncover#i1l1.up#i1.a_minus		///
	i1.uncover#i1f1.up#i1.low 	   		i1.uncover#i1.up#i1.low	   		i1.uncover#i1l1.up#i1.low, 			///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down

reghdfe delta_p ln_pyr_dpw /// Commercial
	i1.uncover /// 
	/* Downgrades (Pre, Current, Post) */  																	///
	i1.uncover#i1f1.down#i1.high 		i1.uncover#i1.down#i1.high 		i1.uncover#i1l1.down#i1.high		///	
	i1.uncover#i1f1.down#i1.a_minus 	i1.uncover#i1.down#i1.a_minus	i1.uncover#i1l1.down#i1.a_minus		///
	i1.uncover#i1f1.down#i1.low			i1.uncover#i1.down#i1.low		i1.uncover#i1l1.down#i1.low 		///
	/* Upgrades (Pre, Current, Post) */  																	///
	i1.uncover#i1f1.up#i1.high 			i1.uncover#i1.up#i1.high		i1.uncover#i1l1.up#i1.high			///  
	i1.uncover#i1f1.up#i1.a_minus		i1.uncover#i1.up#i1.a_minus		i1.uncover#i1l1.up#i1.a_minus		///
	i1.uncover#i1f1.up#i1.low 	   		i1.uncover#i1.up#i1.low	   		i1.uncover#i1l1.up#i1.low 			///	
	if commercial==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo commercial_up_down

esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst 
	
* ------------------------------------------------------------------------------
* ----------- Models for Appendix Table A1
* ------------------------------------------------------------------------------

* These lines are excluded
drop if lob=="fin"
drop if lob=="fidelity"
drop if lob=="war"

eststo clear 

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover /// 
	i1.uncover#i1.down#i1.high i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down

reghdfe delta_p ln_pyr_dpw /// Commercial
	i1.uncover /// 
	i1.uncover#i1.down#i1.high i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low ///
	if commercial==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo commercial_up_down

esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst 	
	
* ------------------------------------------------------------------------------
* ----------- Models for Appendix Table A2
* ------------------------------------------------------------------------------

* These lines are excluded
drop if lob=="fin"
drop if lob=="fidelity"
drop if lob=="war"

eststo clear 

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down

reghdfe delta_p ln_pyr_dpw /// Commercial
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up ///
	if commercial==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo commercial_up_down

esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst 	
	
* ------------------------------------------------------------------------------
* ----------- Models for Appendix Table A3
* ------------------------------------------------------------------------------

eststo clear 

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.down ///
	i1.uncover#i1.up ///
	if commercial==1 & unlimited==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_unlim

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.down ///
	i1.uncover#i1.up ///
	if commercial==1 & unlimited==0, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_lim

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.down ///
	i1.uncover#i1.up ///
	if commercial==1 & mpc_cat=="low", ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_low

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.down ///
	i1.uncover#i1.up ///
	if commercial==1 & mpc_cat=="mid", ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_mid

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.down ///
	i1.uncover#i1.up ///
	if commercial==1 & mpc_cat=="high", ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_high	
	
esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst 		
	
* ------------------------------------------------------------------------------
* ----------- Models for Appendix Table A4
* ------------------------------------------------------------------------------

eststo clear 

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.down#i1.high  i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high  i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low ///
	if commercial==1 & unlimited==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_unlim

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.down#i1.high  i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high  i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low ///
	if commercial==1 & unlimited==0, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_lim

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.down#i1.high  i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high  i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low ///
	if commercial==1 & mpc_cat=="low", ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_low

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.down#i1.high  i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high  i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low ///
	if commercial==1 & mpc_cat=="mid", ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_mid

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.down#i1.high  i1.uncover#i1.down#i1.a_minus i1.uncover#i1.down#i1.low ///
	i1.uncover#i1.up#i1.high  i1.uncover#i1.up#i1.a_minus i1.uncover#i1.up#i1.low ///
	if commercial==1 & mpc_cat=="high", ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_high
	
esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst	
	
* ------------------------------------------------------------------------------
* ----------- Models for Appendix Table A5
* ------------------------------------------------------------------------------

eststo clear 

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up ///
	if commercial==1 & unlimited==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_unlim

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up ///
	if commercial==1 & unlimited==0, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_lim

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up ///
	if commercial==1 & mpc_cat=="low", ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_low

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up ///
	if commercial==1 & mpc_cat=="mid", ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_mid

reghdfe delta_p ln_pyr_dpw /// 
	i1.uncover /// 
	i1.uncover#i1.no_threshold_down i1.uncover#i1.threshold_down   ///
	i1.uncover#i1.no_threshold_up i1.uncover#i1.threshold_up ///
	if commercial==1 & mpc_cat=="high", ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down_high
	
esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst		
	
* ------------------------------------------------------------------------------
* ----------- Model for Appendix Table A6
* ------------------------------------------------------------------------------

use "FullData-2023-0820 - with full ratings", replace

eststo clear 

reghdfe delta_p ln_pyr_dpw /// All lines
	i1.uncover /// 
	i1.uncover#i1.down#i1.app ///
	i1.uncover#i1.down#i1.ap ///
	i1.uncover#i1.down#i1.a ///
	i1.uncover#i1.down#i1.am ///
	i1.uncover#i1.down#i1.bpp ///
	i1.uncover#i1.down#i1.bp ///
	i1.uncover#i1.down#i1.b ///
	i1.uncover#i1.up#i1.ap ///
	i1.uncover#i1.up#i1.a ///
	i1.uncover#i1.up#i1.am ///
	i1.uncover#i1.up#i1.bpp ///
	i1.uncover#i1.up#i1.bp ///
	i1.uncover#i1.up#i1.b ///
	i1.uncover#i1.up#i1.bm ///
	i1.uncover#i1.up#i1.cp ///
	if commercial==1, ///
	absorb(fly_id sly_id) vce(cluster fly_id)
eststo up_down	
	
esttab, ///
	b(4) se(4) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2_within N, labels("Within R2" "Observations") fmt(4 0)) ///
	obslast interaction(" x ") noconst
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	


